#ifndef __FRAME_H__
#define __FRAME_H__

/** Device Protocol Define **/
#define MEIAN_HEAD 0xBEEF

#define CMD_VIDEO_TRNS		    0x0103 /* Video Stream From Device */
#define CMD_MONITOR_DATA_TRANS	    0x0306 /* Audio Stream From Device */

#define FRAME_TYPE_I                 0x0
#define FRAME_TYPE_P                 0x1
typedef struct tagvideoframeheader
{
    int frame_type;
    int pts[2];
    int pack_num;
    int frame_len;
    int fts; /* hhmmss */
}video_frame_header;

#define MA_PKG_HEAD_SIZE sizeof(struct meian_pkg_head_type)
struct meian_pkg_head_type
{
    unsigned short head;
    unsigned short len;
    unsigned short cmd;
    unsigned short reslv;
};

/**
 * only NEED initialize three memebers when NET_USR_CONNECTED:
 *  new_frame_flag = 1, // start a new Frame
 *  first_frame_flag = 1, // first frame should be IFrame
 *  pack_cache_size = 0,
 *
 * the other memebers would be initialized automaticaly.
 */
struct stream_frame_status
{
    video_frame_header header; /* last pack */
    int new_frame_flag; /* 1: start a new frame, 0: again */
    int first_frame_flag; /* init: 1 */
    int begin_pnum; /* init: -1 */
    int end_pnum; /* init: -1 */
    int total_pack; /* init: -1 */
    int last_pnum; /* init: -1 */
    int frame_size; /* init: 0 */
    unsigned char frame[512000];
    unsigned char pack_cache[1500];
    int pack_cache_size; /* init: 0 */

    int audio_frame_size; /* init: 0 */
    unsigned char audio_frame[1024];
};

#define STREAM_FRAME_VIDEO  1
#define STREAM_FRAME_AUDIO  2

int init_stream_frame_status(struct stream_frame_status *stream_frame);

/*
 * get a video/audio frame from input stream packs
 *
 * @param[in] stream_frame structure used to record frame-data and control-status
 * @param[in] buf input stream pack
 * @param[in] len input stream pack length
 * @ret return 0 if frame not interity, return STREAM_FRAME_VIDEO when we got a video frame,
 * return STREAM_FRAME_AUDIO when we got a audio frame.
 */
int get_stream_frame(struct stream_frame_status *stream_frame,char *buf, int len);

#endif


